/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * UserSearchRestaurantGui.java
 *
 * Created on 4 Φεβ 2012, 10:07:44 μμ
 */

package gui;

import HelperClasses.Database.AllRestaurants;
import HelperClasses.Messages.InformationMessage;
import HelperClasses.Messages.TerminateQuestion;
import HelperClasses.PopulateListAndComboBoxes.ComplexItem;
import HelperClasses.PopulateListAndComboBoxes.ComplexItem.cBoxItem;
import HelperClasses.PopulateListAndComboBoxes.ComplexItem.cListItem;
import HelperClasses.PopulateListAndComboBoxes.CreateAreaComboBoxModel;
import HelperClasses.PopulateListAndComboBoxes.CreateCategoryListModel;
import HelperClasses.PopulateListAndComboBoxes.CreatePriceRangeComboBoxModel;
import entertainmentguide.entity.*;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
import manageDataBase.DBManager;

/**
 *
 * 
 */
public class UserSearchRestaurantGui extends javax.swing.JFrame {

    // τιμή για επιλογή listbox/combobox 'not selected'
    private static final int NOT_SELECTED = -1;
    // ο τρέχων χρήστης
    static public  User loggedUser = new User(); 
    // το επιλεγμένο εστιατόριο
    private static Restaurant formRestaurant = new Restaurant();
    // η αξιολόγηση του επιλεγμένου εστιατορίου
    private static Rating formRating = new Rating();
    // η κράτηση του επιλεγμένου εστιατορίου
    private static Reservation formReservation = new Reservation();
    // η περιοχή του επιλεγμένου εστιατορίου
    private static Area formArea = new Area();
     // η κατηγορία του επιλεγμένου εστιατορίου
    private static Category formCategory = new Category();
    // η περιοχή τιμών του επιλεγμένου εστιατορίου
    private static PriceRange formPriceRange = new PriceRange();
    
    /** Creates new form UserSearchRestaurantGui */
    public UserSearchRestaurantGui() {
        initComponents();
        
        // επιλέγω ως αρχική τιμή, την πρώτη σε κάθε λίστα
        CategoryList.setSelectedIndex(0);
        AreaComboBox.setSelectedIndex(0);
        PriceRangeComboBox.setSelectedIndex(0);
        // Αρχικοποίηση του πίνακα με άδειες γραμμές
        ArrayList<Restaurant> empty = new ArrayList<>() ;
        empty.clear();
        ResultsTable.setModel(AllRestaurants.forTable(empty));
        // αφαιρώ την πρώτη στήλη από τον πίνακα, ώστε το ID να μην εμφανίζεται
        TableColumn tcDeleteTable = ResultsTable.getColumnModel().getColumn(0);
        ResultsTable.getColumnModel().removeColumn(tcDeleteTable);
        // ρύθμιση μονής επιλογής στον πίνακα 
        ResultsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ShowDialog = new javax.swing.JDialog();
        jLabel19 = new javax.swing.JLabel();
        RestaurantNameLabel = new javax.swing.JLabel();
        RestaurantPhotoPanel = new javax.swing.JPanel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        RestaurantCategoryLabel = new javax.swing.JLabel();
        RestaurantInformationLabel = new javax.swing.JLabel();
        RestaurantPriceLabel = new javax.swing.JLabel();
        RestaurantAddressLabel = new javax.swing.JLabel();
        RestaurantPhoneLabel = new javax.swing.JLabel();
        jLabel31 = new javax.swing.JLabel();
        RestaurantMapPanel = new javax.swing.JPanel();
        RestaurantJXMapKit = new org.jdesktop.swingx.JXMapKit();
        CloseButton = new javax.swing.JButton();
        jLabel32 = new javax.swing.JLabel();
        RestaurantMoreScrollPane = new javax.swing.JScrollPane();
        RestaurantMoreTextArea = new javax.swing.JTextArea();
        jLabel33 = new javax.swing.JLabel();
        jLabel34 = new javax.swing.JLabel();
        jLabel35 = new javax.swing.JLabel();
        jLabel36 = new javax.swing.JLabel();
        QualityStarRater = new restaurantguide.utils.StarRater();
        PriceStarRater = new restaurantguide.utils.StarRater();
        ServiceStarRater = new restaurantguide.utils.StarRater();
        AverageStarRater = new restaurantguide.utils.StarRater();
        RateDialog = new javax.swing.JDialog();
        jLabel20 = new javax.swing.JLabel();
        RateRestaurantNameLabel = new javax.swing.JLabel();
        jLabel37 = new javax.swing.JLabel();
        jLabel38 = new javax.swing.JLabel();
        jLabel39 = new javax.swing.JLabel();
        RateServiceStarRater = new restaurantguide.utils.StarRater();
        RatePriceStarRater = new restaurantguide.utils.StarRater();
        RateQualityStarRater = new restaurantguide.utils.StarRater();
        RateSubmitButton = new javax.swing.JButton();
        jLabel40 = new javax.swing.JLabel();
        jLabel41 = new javax.swing.JLabel();
        RateAverageLabel = new javax.swing.JLabel();
        RateAverageStarRater = new restaurantguide.utils.StarRater();
        RateCloseButton = new javax.swing.JButton();
        ReserveDialog = new javax.swing.JDialog();
        jLabel26 = new javax.swing.JLabel();
        ReserveRestaurantNameLabel = new javax.swing.JLabel();
        ReserveSubmitButton = new javax.swing.JButton();
        ReserveStateLabel = new javax.swing.JLabel();
        ReserveConfirmButton = new javax.swing.JButton();
        ReserveStoreButton = new javax.swing.JButton();
        ReserveCloseButton = new javax.swing.JButton();
        ReserveColorPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        BackgroundColorPanel = new javax.swing.JPanel();
        SearchRestaurantButton = new javax.swing.JButton();
        StartServiceButton = new javax.swing.JButton();
        StopServiceButton = new javax.swing.JButton();
        ExitButton = new javax.swing.JButton();
        LogoLabel = new javax.swing.JLabel();
        TitleLabel = new javax.swing.JLabel();
        SearchPanel = new javax.swing.JPanel();
        NameLabel = new javax.swing.JLabel();
        NameTextField = new javax.swing.JTextField();
        AreaLabel = new javax.swing.JLabel();
        AreaComboBox = new javax.swing.JComboBox();
        CategoryLabel = new javax.swing.JLabel();
        CategoryScrollPane = new javax.swing.JScrollPane();
        CategoryList = new javax.swing.JList();
        PriceRangeLabel = new javax.swing.JLabel();
        PriceRangeComboBox = new javax.swing.JComboBox();
        SearchButton = new javax.swing.JButton();
        ClearButton = new javax.swing.JButton();
        ResultsTitleLabel = new javax.swing.JLabel();
        ResultsScrollPane = new javax.swing.JScrollPane();
        ResultsTable = new javax.swing.JTable();
        ShowButton = new javax.swing.JButton();
        RateButton = new javax.swing.JButton();
        ReserveButton = new javax.swing.JButton();

        ShowDialog.setTitle("Προβολή Εστιατορίου");
        ShowDialog.setIconImages(null);
        ShowDialog.setMinimumSize(new java.awt.Dimension(504, 640));
        ShowDialog.setModal(true);
        ShowDialog.setPreferredSize(new java.awt.Dimension(504, 640));
        ShowDialog.setResizable(false);
        ShowDialog.getContentPane().setLayout(null);

        jLabel19.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel19.setText("Προβολή Εστιατορίου :");
        ShowDialog.getContentPane().add(jLabel19);
        jLabel19.setBounds(20, 11, 143, 15);

        RestaurantNameLabel.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        RestaurantNameLabel.setText("Το φίλεμα");
        ShowDialog.getContentPane().add(RestaurantNameLabel);
        RestaurantNameLabel.setBounds(170, 11, 310, 15);

        RestaurantPhotoPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));
        RestaurantPhotoPanel.setLayout(null);
        ShowDialog.getContentPane().add(RestaurantPhotoPanel);
        RestaurantPhotoPanel.setBounds(20, 53, 0, 0);

        jLabel21.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jLabel21.setText("Κατηγορία :");
        ShowDialog.getContentPane().add(jLabel21);
        jLabel21.setBounds(156, 138, 56, 13);

        jLabel22.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jLabel22.setText("Πληροφορίες :");
        ShowDialog.getContentPane().add(jLabel22);
        jLabel22.setBounds(142, 118, 69, 13);

        jLabel23.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jLabel23.setText("Τιμές :");
        ShowDialog.getContentPane().add(jLabel23);
        jLabel23.setBounds(181, 98, 30, 13);

        jLabel24.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jLabel24.setText("Τηλ. :");
        ShowDialog.getContentPane().add(jLabel24);
        jLabel24.setBounds(183, 78, 28, 13);

        jLabel25.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jLabel25.setText("Διεύθυνση :");
        ShowDialog.getContentPane().add(jLabel25);
        jLabel25.setBounds(155, 58, 56, 13);

        RestaurantCategoryLabel.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        RestaurantCategoryLabel.setText("jLabel12");
        RestaurantCategoryLabel.setPreferredSize(new java.awt.Dimension(240, 14));
        ShowDialog.getContentPane().add(RestaurantCategoryLabel);
        RestaurantCategoryLabel.setBounds(220, 138, 240, 14);

        RestaurantInformationLabel.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        RestaurantInformationLabel.setText("jLabel11");
        RestaurantInformationLabel.setPreferredSize(new java.awt.Dimension(240, 14));
        ShowDialog.getContentPane().add(RestaurantInformationLabel);
        RestaurantInformationLabel.setBounds(220, 118, 240, 14);

        RestaurantPriceLabel.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        RestaurantPriceLabel.setText("jLabel10");
        RestaurantPriceLabel.setPreferredSize(new java.awt.Dimension(240, 14));
        RestaurantPriceLabel.setRequestFocusEnabled(false);
        ShowDialog.getContentPane().add(RestaurantPriceLabel);
        RestaurantPriceLabel.setBounds(220, 98, 240, 14);

        RestaurantAddressLabel.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        RestaurantAddressLabel.setText("jLabel8");
        RestaurantAddressLabel.setPreferredSize(new java.awt.Dimension(240, 14));
        ShowDialog.getContentPane().add(RestaurantAddressLabel);
        RestaurantAddressLabel.setBounds(220, 58, 240, 14);

        RestaurantPhoneLabel.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        RestaurantPhoneLabel.setText("jLabel9");
        RestaurantPhoneLabel.setPreferredSize(new java.awt.Dimension(240, 14));
        ShowDialog.getContentPane().add(RestaurantPhoneLabel);
        RestaurantPhoneLabel.setBounds(220, 78, 240, 14);

        jLabel31.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel31.setText("Χάρτης");
        ShowDialog.getContentPane().add(jLabel31);
        jLabel31.setBounds(20, 296, 45, 15);

        RestaurantMapPanel.setLayout(null);

        RestaurantJXMapKit.setDefaultProvider(org.jdesktop.swingx.JXMapKit.DefaultProviders.OpenStreetMaps);
        RestaurantMapPanel.add(RestaurantJXMapKit);
        RestaurantJXMapKit.setBounds(5, 5, 464, 229);

        CloseButton.setText("Κλείσιμο");
        CloseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CloseButtonActionPerformed(evt);
            }
        });
        RestaurantMapPanel.add(CloseButton);
        CloseButton.setBounds(151, 240, 140, 23);

        ShowDialog.getContentPane().add(RestaurantMapPanel);
        RestaurantMapPanel.setBounds(20, 322, 474, 274);

        jLabel32.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel32.setText("Περισσότερα για το εστιατόριο");
        ShowDialog.getContentPane().add(jLabel32);
        jLabel32.setBounds(20, 175, 190, 15);

        RestaurantMoreTextArea.setColumns(20);
        RestaurantMoreTextArea.setEditable(false);
        RestaurantMoreTextArea.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        RestaurantMoreTextArea.setRows(5);
        RestaurantMoreScrollPane.setViewportView(RestaurantMoreTextArea);

        ShowDialog.getContentPane().add(RestaurantMoreScrollPane);
        RestaurantMoreScrollPane.setBounds(20, 198, 166, 80);

        jLabel33.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel33.setText("Ποιότητα :");
        ShowDialog.getContentPane().add(jLabel33);
        jLabel33.setBounds(265, 198, 59, 14);

        jLabel34.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel34.setText("Τιμές :");
        ShowDialog.getContentPane().add(jLabel34);
        jLabel34.setBounds(289, 218, 35, 14);

        jLabel35.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel35.setText("Χρόνος Εξυπηρέτησης :");
        ShowDialog.getContentPane().add(jLabel35);
        jLabel35.setBounds(194, 242, 130, 14);

        jLabel36.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel36.setText("Μέση Βαθμολογία :");
        ShowDialog.getContentPane().add(jLabel36);
        jLabel36.setBounds(219, 262, 105, 14);

        QualityStarRater.setEnabled(false);
        QualityStarRater.setStars(10);
        QualityStarRater.setVerifyInputWhenFocusTarget(false);

        javax.swing.GroupLayout QualityStarRaterLayout = new javax.swing.GroupLayout(QualityStarRater);
        QualityStarRater.setLayout(QualityStarRaterLayout);
        QualityStarRaterLayout.setHorizontalGroup(
            QualityStarRaterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 160, Short.MAX_VALUE)
        );
        QualityStarRaterLayout.setVerticalGroup(
            QualityStarRaterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        ShowDialog.getContentPane().add(QualityStarRater);
        QualityStarRater.setBounds(328, 196, 160, 16);

        PriceStarRater.setEnabled(false);
        PriceStarRater.setStars(10);

        javax.swing.GroupLayout PriceStarRaterLayout = new javax.swing.GroupLayout(PriceStarRater);
        PriceStarRater.setLayout(PriceStarRaterLayout);
        PriceStarRaterLayout.setHorizontalGroup(
            PriceStarRaterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 160, Short.MAX_VALUE)
        );
        PriceStarRaterLayout.setVerticalGroup(
            PriceStarRaterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        ShowDialog.getContentPane().add(PriceStarRater);
        PriceStarRater.setBounds(328, 218, 160, 16);

        ServiceStarRater.setEnabled(false);
        ServiceStarRater.setStars(10);

        javax.swing.GroupLayout ServiceStarRaterLayout = new javax.swing.GroupLayout(ServiceStarRater);
        ServiceStarRater.setLayout(ServiceStarRaterLayout);
        ServiceStarRaterLayout.setHorizontalGroup(
            ServiceStarRaterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 160, Short.MAX_VALUE)
        );
        ServiceStarRaterLayout.setVerticalGroup(
            ServiceStarRaterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        ShowDialog.getContentPane().add(ServiceStarRater);
        ServiceStarRater.setBounds(328, 240, 160, 16);

        AverageStarRater.setEnabled(false);
        AverageStarRater.setStars(10);

        javax.swing.GroupLayout AverageStarRaterLayout = new javax.swing.GroupLayout(AverageStarRater);
        AverageStarRater.setLayout(AverageStarRaterLayout);
        AverageStarRaterLayout.setHorizontalGroup(
            AverageStarRaterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 160, Short.MAX_VALUE)
        );
        AverageStarRaterLayout.setVerticalGroup(
            AverageStarRaterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        ShowDialog.getContentPane().add(AverageStarRater);
        AverageStarRater.setBounds(328, 262, 160, 16);

        RateDialog.setTitle("Αξιολόγηση Εστιατορίου");
        RateDialog.setMinimumSize(new java.awt.Dimension(438, 380));
        RateDialog.setModal(true);
        RateDialog.setPreferredSize(new java.awt.Dimension(438, 330));
        RateDialog.setResizable(false);
        RateDialog.addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                RateDialogWindowActivated(evt);
            }
        });
        RateDialog.getContentPane().setLayout(null);

        jLabel20.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel20.setText("Αξιολόγηση Εστιατορίου :");
        RateDialog.getContentPane().add(jLabel20);
        jLabel20.setBounds(10, 11, 139, 15);

        RateRestaurantNameLabel.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        RateRestaurantNameLabel.setText("Το φίλεμα");
        RateDialog.getContentPane().add(RateRestaurantNameLabel);
        RateRestaurantNameLabel.setBounds(160, 11, 260, 15);

        jLabel37.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel37.setText("Ποιότητα :");
        RateDialog.getContentPane().add(jLabel37);
        jLabel37.setBounds(127, 64, 59, 14);

        jLabel38.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel38.setText("Τιμές :");
        RateDialog.getContentPane().add(jLabel38);
        jLabel38.setBounds(151, 84, 35, 14);

        jLabel39.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel39.setText("Χρόνος Εξυπηρέτησης :");
        RateDialog.getContentPane().add(jLabel39);
        jLabel39.setBounds(56, 106, 130, 14);

        RateServiceStarRater.setStars(10);
        RateServiceStarRater.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                RateServiceStarRaterMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout RateServiceStarRaterLayout = new javax.swing.GroupLayout(RateServiceStarRater);
        RateServiceStarRater.setLayout(RateServiceStarRaterLayout);
        RateServiceStarRaterLayout.setHorizontalGroup(
            RateServiceStarRaterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 160, Short.MAX_VALUE)
        );
        RateServiceStarRaterLayout.setVerticalGroup(
            RateServiceStarRaterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        RateDialog.getContentPane().add(RateServiceStarRater);
        RateServiceStarRater.setBounds(190, 106, 160, 16);

        RatePriceStarRater.setStars(10);
        RatePriceStarRater.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                RatePriceStarRaterMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout RatePriceStarRaterLayout = new javax.swing.GroupLayout(RatePriceStarRater);
        RatePriceStarRater.setLayout(RatePriceStarRaterLayout);
        RatePriceStarRaterLayout.setHorizontalGroup(
            RatePriceStarRaterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 160, Short.MAX_VALUE)
        );
        RatePriceStarRaterLayout.setVerticalGroup(
            RatePriceStarRaterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        RateDialog.getContentPane().add(RatePriceStarRater);
        RatePriceStarRater.setBounds(190, 84, 160, 16);

        RateQualityStarRater.setStars(10);
        RateQualityStarRater.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                RateQualityStarRaterMouseReleased(evt);
            }
        });
        RateQualityStarRater.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                RateQualityStarRaterPropertyChange(evt);
            }
        });

        javax.swing.GroupLayout RateQualityStarRaterLayout = new javax.swing.GroupLayout(RateQualityStarRater);
        RateQualityStarRater.setLayout(RateQualityStarRaterLayout);
        RateQualityStarRaterLayout.setHorizontalGroup(
            RateQualityStarRaterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 160, Short.MAX_VALUE)
        );
        RateQualityStarRaterLayout.setVerticalGroup(
            RateQualityStarRaterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        RateDialog.getContentPane().add(RateQualityStarRater);
        RateQualityStarRater.setBounds(190, 62, 160, 16);

        RateSubmitButton.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        RateSubmitButton.setText("Υποβολή");
        RateSubmitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RateSubmitButtonActionPerformed(evt);
            }
        });
        RateDialog.getContentPane().add(RateSubmitButton);
        RateSubmitButton.setBounds(148, 152, 150, 21);

        jLabel40.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel40.setText("Μέση Βαθμολογία :");
        RateDialog.getContentPane().add(jLabel40);
        jLabel40.setBounds(104, 205, 105, 14);

        jLabel41.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel41.setText("/10");
        RateDialog.getContentPane().add(jLabel41);
        jLabel41.setBounds(309, 205, 20, 14);

        RateAverageLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        RateAverageLabel.setText("(Άθροισμα/3)");
        RateDialog.getContentPane().add(RateAverageLabel);
        RateAverageLabel.setBounds(227, 205, 76, 14);

        RateAverageStarRater.setEnabled(false);
        RateAverageStarRater.setStars(10);

        javax.swing.GroupLayout RateAverageStarRaterLayout = new javax.swing.GroupLayout(RateAverageStarRater);
        RateAverageStarRater.setLayout(RateAverageStarRaterLayout);
        RateAverageStarRaterLayout.setHorizontalGroup(
            RateAverageStarRaterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 160, Short.MAX_VALUE)
        );
        RateAverageStarRaterLayout.setVerticalGroup(
            RateAverageStarRaterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        RateDialog.getContentPane().add(RateAverageStarRater);
        RateAverageStarRater.setBounds(143, 237, 160, 16);

        RateCloseButton.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        RateCloseButton.setText("Κλείσιμο");
        RateCloseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RateCloseButtonActionPerformed(evt);
            }
        });
        RateDialog.getContentPane().add(RateCloseButton);
        RateCloseButton.setBounds(153, 296, 140, 21);

        ReserveDialog.setTitle("Κράτηση Εστιατορίου");
        ReserveDialog.setLocationByPlatform(true);
        ReserveDialog.setMinimumSize(new java.awt.Dimension(522, 400));
        ReserveDialog.setModal(true);
        ReserveDialog.setPreferredSize(new java.awt.Dimension(522, 400));
        ReserveDialog.setResizable(false);
        ReserveDialog.getContentPane().setLayout(null);

        jLabel26.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel26.setText("Κράτηση για το Εστιατόριο :");
        ReserveDialog.getContentPane().add(jLabel26);
        jLabel26.setBounds(10, 0, 180, 30);

        ReserveRestaurantNameLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        ReserveRestaurantNameLabel.setText("Το φίλεμα");
        ReserveDialog.getContentPane().add(ReserveRestaurantNameLabel);
        ReserveRestaurantNameLabel.setBounds(190, 8, 320, 15);

        ReserveSubmitButton.setText("Αίτηση Κράτησης");
        ReserveSubmitButton.setMaximumSize(new java.awt.Dimension(170, 40));
        ReserveSubmitButton.setMinimumSize(new java.awt.Dimension(170, 40));
        ReserveSubmitButton.setPreferredSize(new java.awt.Dimension(170, 40));
        ReserveSubmitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ReserveSubmitButtonActionPerformed(evt);
            }
        });
        ReserveDialog.getContentPane().add(ReserveSubmitButton);
        ReserveSubmitButton.setBounds(40, 80, 170, 40);

        ReserveStateLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        ReserveStateLabel.setText("Ανενεργή");
        ReserveDialog.getContentPane().add(ReserveStateLabel);
        ReserveStateLabel.setBounds(350, 150, 60, 30);

        ReserveConfirmButton.setText("Επιβεβαίωση Κράτησης");
        ReserveConfirmButton.setMaximumSize(new java.awt.Dimension(170, 40));
        ReserveConfirmButton.setMinimumSize(new java.awt.Dimension(170, 40));
        ReserveConfirmButton.setPreferredSize(new java.awt.Dimension(170, 40));
        ReserveConfirmButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ReserveConfirmButtonActionPerformed(evt);
            }
        });
        ReserveDialog.getContentPane().add(ReserveConfirmButton);
        ReserveConfirmButton.setBounds(40, 145, 170, 40);

        ReserveStoreButton.setText("Αποθήκευση Κράτησης");
        ReserveStoreButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ReserveStoreButtonActionPerformed(evt);
            }
        });
        ReserveDialog.getContentPane().add(ReserveStoreButton);
        ReserveStoreButton.setBounds(40, 210, 170, 40);

        ReserveCloseButton.setText("Κλείσιμο");
        ReserveCloseButton.setMaximumSize(new java.awt.Dimension(170, 40));
        ReserveCloseButton.setMinimumSize(new java.awt.Dimension(170, 40));
        ReserveCloseButton.setPreferredSize(new java.awt.Dimension(170, 40));
        ReserveCloseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ReserveCloseButtonActionPerformed(evt);
            }
        });
        ReserveDialog.getContentPane().add(ReserveCloseButton);
        ReserveCloseButton.setBounds(40, 280, 170, 40);

        ReserveColorPanel.setBackground(new java.awt.Color(153, 153, 255));

        javax.swing.GroupLayout ReserveColorPanelLayout = new javax.swing.GroupLayout(ReserveColorPanel);
        ReserveColorPanel.setLayout(ReserveColorPanelLayout);
        ReserveColorPanelLayout.setHorizontalGroup(
            ReserveColorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 234, Short.MAX_VALUE)
        );
        ReserveColorPanelLayout.setVerticalGroup(
            ReserveColorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        ReserveDialog.getContentPane().add(ReserveColorPanel);
        ReserveColorPanel.setBounds(270, 220, 234, 100);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("Κατάσταση Κράτησης");
        ReserveDialog.getContentPane().add(jLabel1);
        jLabel1.setBounds(310, 110, 121, 14);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Restaurant Guide");
        setMinimumSize(new java.awt.Dimension(800, 800));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });
        getContentPane().setLayout(null);

        BackgroundColorPanel.setBackground(new java.awt.Color(255, 153, 102));
        BackgroundColorPanel.setPreferredSize(new java.awt.Dimension(180, 500));
        BackgroundColorPanel.setRequestFocusEnabled(false);
        BackgroundColorPanel.setLayout(null);

        SearchRestaurantButton.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        SearchRestaurantButton.setText("Αναζήτηση Εστιατορίου");
        SearchRestaurantButton.setEnabled(false);
        SearchRestaurantButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SearchRestaurantButtonActionPerformed(evt);
            }
        });
        BackgroundColorPanel.add(SearchRestaurantButton);
        SearchRestaurantButton.setBounds(10, 38, 150, 21);

        StartServiceButton.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        StartServiceButton.setText("Εκκίνηση Υπηρεσίας");
        StartServiceButton.setMaximumSize(new java.awt.Dimension(137, 23));
        StartServiceButton.setMinimumSize(new java.awt.Dimension(137, 23));
        StartServiceButton.setPreferredSize(new java.awt.Dimension(137, 23));
        StartServiceButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StartServiceButtonActionPerformed(evt);
            }
        });
        BackgroundColorPanel.add(StartServiceButton);
        StartServiceButton.setBounds(10, 79, 150, 23);

        StopServiceButton.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        StopServiceButton.setText("Παύση Υπηρεσίας");
        StopServiceButton.setMaximumSize(new java.awt.Dimension(137, 23));
        StopServiceButton.setMinimumSize(new java.awt.Dimension(137, 23));
        StopServiceButton.setPreferredSize(new java.awt.Dimension(137, 23));
        StopServiceButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StopServiceButtonActionPerformed(evt);
            }
        });
        BackgroundColorPanel.add(StopServiceButton);
        StopServiceButton.setBounds(10, 120, 150, 23);

        ExitButton.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        ExitButton.setText("Έξοδος");
        ExitButton.setMaximumSize(new java.awt.Dimension(137, 23));
        ExitButton.setMinimumSize(new java.awt.Dimension(137, 23));
        ExitButton.setPreferredSize(new java.awt.Dimension(137, 23));
        ExitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExitButtonActionPerformed(evt);
            }
        });
        BackgroundColorPanel.add(ExitButton);
        ExitButton.setBounds(10, 161, 150, 23);

        getContentPane().add(BackgroundColorPanel);
        BackgroundColorPanel.setBounds(0, 126, 180, 500);

        LogoLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/thessaloniki-restaurants.jpg"))); // NOI18N
        getContentPane().add(LogoLabel);
        LogoLabel.setBounds(0, 0, 400, 120);

        TitleLabel.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        TitleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        TitleLabel.setText("Αναζήτηση Εστιατορίου");
        TitleLabel.setPreferredSize(new java.awt.Dimension(310, 30));
        getContentPane().add(TitleLabel);
        TitleLabel.setBounds(410, 50, 310, 30);

        SearchPanel.setBackground(new java.awt.Color(255, 255, 204));
        SearchPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        SearchPanel.setLayout(null);

        NameLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        NameLabel.setText("Όνομα Εστιατορίου :");
        SearchPanel.add(NameLabel);
        NameLabel.setBounds(12, 16, 115, 14);
        SearchPanel.add(NameTextField);
        NameTextField.setBounds(137, 13, 350, 20);

        AreaLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        AreaLabel.setText("Περιοχή :");
        SearchPanel.add(AreaLabel);
        AreaLabel.setBounds(77, 54, 50, 14);

        AreaComboBox.setModel(areaComboBoxModel());
        AreaComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                AreaComboBoxItemStateChanged(evt);
            }
        });
        SearchPanel.add(AreaComboBox);
        AreaComboBox.setBounds(137, 51, 350, 20);

        CategoryLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        CategoryLabel.setText("Κατηγορία :");
        SearchPanel.add(CategoryLabel);
        CategoryLabel.setBounds(62, 121, 65, 14);

        CategoryList.setModel(categoryListModel());
        CategoryList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                CategoryListValueChanged(evt);
            }
        });
        CategoryScrollPane.setViewportView(CategoryList);

        SearchPanel.add(CategoryScrollPane);
        CategoryScrollPane.setBounds(137, 89, 350, 80);

        PriceRangeLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        PriceRangeLabel.setText("Εύρος Τιμών :");
        SearchPanel.add(PriceRangeLabel);
        PriceRangeLabel.setBounds(52, 178, 75, 14);

        PriceRangeComboBox.setModel(priceComboBoxModel());
        PriceRangeComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                PriceRangeComboBoxItemStateChanged(evt);
            }
        });
        SearchPanel.add(PriceRangeComboBox);
        PriceRangeComboBox.setBounds(137, 185, 350, 20);

        SearchButton.setText("Αναζήτηση");
        SearchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SearchButtonActionPerformed(evt);
            }
        });
        SearchPanel.add(SearchButton);
        SearchButton.setBounds(137, 220, 131, 23);

        ClearButton.setText("Καθαρισμός Φίλτρων");
        ClearButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ClearButtonActionPerformed(evt);
            }
        });
        SearchPanel.add(ClearButton);
        ClearButton.setBounds(280, 220, 200, 23);

        getContentPane().add(SearchPanel);
        SearchPanel.setBounds(190, 126, 520, 270);

        ResultsTitleLabel.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        ResultsTitleLabel.setText("Αποτελέσματα Αναζήτησης");
        getContentPane().add(ResultsTitleLabel);
        ResultsTitleLabel.setBounds(330, 410, 240, 22);

        ResultsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Όνομα", "Διεύθυνση", "Περιοχή", "Τηλέφωνο", "Κατηγορία"
            }
        ));
        ResultsScrollPane.setViewportView(ResultsTable);

        getContentPane().add(ResultsScrollPane);
        ResultsScrollPane.setBounds(190, 440, 560, 140);

        ShowButton.setText("Προβολή");
        ShowButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ShowButtonActionPerformed(evt);
            }
        });
        getContentPane().add(ShowButton);
        ShowButton.setBounds(210, 590, 150, 23);

        RateButton.setText("Αξιολόγηση");
        RateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RateButtonActionPerformed(evt);
            }
        });
        getContentPane().add(RateButton);
        RateButton.setBounds(370, 590, 150, 23);

        ReserveButton.setText("Κράτηση");
        ReserveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ReserveButtonActionPerformed(evt);
            }
        });
        getContentPane().add(ReserveButton);
        ReserveButton.setBounds(530, 590, 150, 23);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void SearchRestaurantButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SearchRestaurantButtonActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_SearchRestaurantButtonActionPerformed

    private void StartServiceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StartServiceButtonActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_StartServiceButtonActionPerformed

    private void StopServiceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StopServiceButtonActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_StopServiceButtonActionPerformed

    private void ExitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExitButtonActionPerformed
        UserMainGui.loggedUser = UserSearchRestaurantGui.loggedUser;
        JFrame UserMainForm = new UserMainGui();
        UserMainForm.setBounds(50, 100, 800, 800);
        UserMainForm.setLocationRelativeTo(null); // possition center of screen
        UserMainForm.setResizable(false); // not resizeable
        UserMainForm.setVisible(true); // show AdministratorMain
        dispose();
}//GEN-LAST:event_ExitButtonActionPerformed

    private void AreaComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_AreaComboBoxItemStateChanged
        // TODO add your handling code here:
}//GEN-LAST:event_AreaComboBoxItemStateChanged

    private void CategoryListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_CategoryListValueChanged
        // TODO add your handling code here:
}//GEN-LAST:event_CategoryListValueChanged

    private void PriceRangeComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_PriceRangeComboBoxItemStateChanged
        // TODO add your handling code here:
}//GEN-LAST:event_PriceRangeComboBoxItemStateChanged

    private void SearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SearchButtonActionPerformed
        findRestaurants();
    }//GEN-LAST:event_SearchButtonActionPerformed

    private void ClearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClearButtonActionPerformed
        // αρχικοποίηση των τιμών
        NameTextField.setText("");
        // επιλέγω ως αρχική τιμή, την πρώτη σε κάθε λίστα
        CategoryList.setSelectedIndex(0);
        // υποχρεώνω την λίστα να περιλάβει την επιλεγμένη κατηγορία στο οπτικό κομμάτι της 
        CategoryList.ensureIndexIsVisible(CategoryList.getSelectedIndex());
        AreaComboBox.setSelectedIndex(0);
        PriceRangeComboBox.setSelectedIndex(0);
    }//GEN-LAST:event_ClearButtonActionPerformed

    private void ShowButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ShowButtonActionPerformed
        showRestaurantDialog();
    }//GEN-LAST:event_ShowButtonActionPerformed

    private void RateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RateButtonActionPerformed
        rateRestaurantDialog();
    }//GEN-LAST:event_RateButtonActionPerformed

    private void ReserveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ReserveButtonActionPerformed
        reserveRestaurantDialog();
    }//GEN-LAST:event_ReserveButtonActionPerformed

    private void CloseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CloseButtonActionPerformed
        ShowDialog.dispose();
    }//GEN-LAST:event_CloseButtonActionPerformed

    private void RateSubmitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RateSubmitButtonActionPerformed
       formUpdateRatingFromUser();
    }//GEN-LAST:event_RateSubmitButtonActionPerformed

    private void RateCloseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RateCloseButtonActionPerformed
        RateDialog.dispose();
    }//GEN-LAST:event_RateCloseButtonActionPerformed

    private void ReserveSubmitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ReserveSubmitButtonActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_ReserveSubmitButtonActionPerformed

    private void ReserveConfirmButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ReserveConfirmButtonActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_ReserveConfirmButtonActionPerformed

    private void ReserveStoreButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ReserveStoreButtonActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_ReserveStoreButtonActionPerformed

    private void ReserveCloseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ReserveCloseButtonActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_ReserveCloseButtonActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
       TerminateQuestion.windowClosing(this);        
    }//GEN-LAST:event_formWindowClosing

    private void RateDialogWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_RateDialogWindowActivated
               
    }//GEN-LAST:event_RateDialogWindowActivated

    private void RateQualityStarRaterPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_RateQualityStarRaterPropertyChange
            
       
    }//GEN-LAST:event_RateQualityStarRaterPropertyChange

    private void RateQualityStarRaterMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RateQualityStarRaterMouseReleased
        // υπολόγισε τον μέσο όρο της αξιολόγησης
        // και ενημέρωσε την φόρμα RateDialog
        calculateFormAverageStarRater();  
    }//GEN-LAST:event_RateQualityStarRaterMouseReleased

    private void RatePriceStarRaterMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RatePriceStarRaterMouseReleased
        // υπολόγισε τον μέσο όρο της αξιολόγησης
        // και ενημέρωσε την φόρμα RateDialog
        calculateFormAverageStarRater();  
    }//GEN-LAST:event_RatePriceStarRaterMouseReleased

    private void RateServiceStarRaterMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RateServiceStarRaterMouseReleased
        // υπολόγισε τον μέσο όρο της αξιολόγησης
        // και ενημέρωσε την φόρμα RateDialog
        calculateFormAverageStarRater();  
    }//GEN-LAST:event_RateServiceStarRaterMouseReleased

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new UserSearchRestaurantGui().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox AreaComboBox;
    private javax.swing.JLabel AreaLabel;
    private restaurantguide.utils.StarRater AverageStarRater;
    private javax.swing.JPanel BackgroundColorPanel;
    private javax.swing.JLabel CategoryLabel;
    private javax.swing.JList CategoryList;
    private javax.swing.JScrollPane CategoryScrollPane;
    private javax.swing.JButton ClearButton;
    private javax.swing.JButton CloseButton;
    private javax.swing.JButton ExitButton;
    private javax.swing.JLabel LogoLabel;
    private javax.swing.JLabel NameLabel;
    private javax.swing.JTextField NameTextField;
    private javax.swing.JComboBox PriceRangeComboBox;
    private javax.swing.JLabel PriceRangeLabel;
    private restaurantguide.utils.StarRater PriceStarRater;
    private restaurantguide.utils.StarRater QualityStarRater;
    private javax.swing.JLabel RateAverageLabel;
    private restaurantguide.utils.StarRater RateAverageStarRater;
    private javax.swing.JButton RateButton;
    private javax.swing.JButton RateCloseButton;
    private javax.swing.JDialog RateDialog;
    private restaurantguide.utils.StarRater RatePriceStarRater;
    private restaurantguide.utils.StarRater RateQualityStarRater;
    private javax.swing.JLabel RateRestaurantNameLabel;
    private restaurantguide.utils.StarRater RateServiceStarRater;
    private javax.swing.JButton RateSubmitButton;
    private javax.swing.JButton ReserveButton;
    private javax.swing.JButton ReserveCloseButton;
    private javax.swing.JPanel ReserveColorPanel;
    private javax.swing.JButton ReserveConfirmButton;
    private javax.swing.JDialog ReserveDialog;
    private javax.swing.JLabel ReserveRestaurantNameLabel;
    private javax.swing.JLabel ReserveStateLabel;
    private javax.swing.JButton ReserveStoreButton;
    private javax.swing.JButton ReserveSubmitButton;
    private javax.swing.JLabel RestaurantAddressLabel;
    private javax.swing.JLabel RestaurantCategoryLabel;
    private javax.swing.JLabel RestaurantInformationLabel;
    private org.jdesktop.swingx.JXMapKit RestaurantJXMapKit;
    private javax.swing.JPanel RestaurantMapPanel;
    private javax.swing.JScrollPane RestaurantMoreScrollPane;
    private javax.swing.JTextArea RestaurantMoreTextArea;
    private javax.swing.JLabel RestaurantNameLabel;
    private javax.swing.JLabel RestaurantPhoneLabel;
    private javax.swing.JPanel RestaurantPhotoPanel;
    private javax.swing.JLabel RestaurantPriceLabel;
    private javax.swing.JScrollPane ResultsScrollPane;
    private javax.swing.JTable ResultsTable;
    private javax.swing.JLabel ResultsTitleLabel;
    private javax.swing.JButton SearchButton;
    private javax.swing.JPanel SearchPanel;
    private javax.swing.JButton SearchRestaurantButton;
    private restaurantguide.utils.StarRater ServiceStarRater;
    private javax.swing.JButton ShowButton;
    private javax.swing.JDialog ShowDialog;
    private javax.swing.JButton StartServiceButton;
    private javax.swing.JButton StopServiceButton;
    private javax.swing.JLabel TitleLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel41;
    // End of variables declaration//GEN-END:variables

      public ListModel categoryListModel(){
        //δημιουργώ περιεχόμενα για το category Jlist
        DefaultListModel dlm =  (DefaultListModel) CreateCategoryListModel.getModel();
        //προσθέτω πρώτη γραμμή αδιάφορης επιλογής -> τιμή NOT_SELECTED
        dlm.insertElementAt(new cListItem("ΕΠΙΛΕΞΤΕ ΑΝΑΖΗΤΗΣΗ ΚΑΤΗΓΟΡΙΑΣ",NOT_SELECTED), 0);
        return  dlm;
    }
    
    public ComboBoxModel areaComboBoxModel(){
        //δημιουργώ περιεχόμενα για το Area ComboBox
        DefaultComboBoxModel dlm =  (DefaultComboBoxModel) CreateAreaComboBoxModel.getModel();
        //προσθέτω πρώτη γραμμή αδιάφορης επιλογής -> τιμή NOT_SELECTED
        dlm.insertElementAt(new cBoxItem("ΕΠΙΛΕΞΤΕ ΑΝΑΖΗΤΗΣΗ ΠΕΡΙΟΧΗΣ",NOT_SELECTED), 0);
        return  dlm;
    }
    
    public ComboBoxModel priceComboBoxModel(){
        //δημιουργώ περιεχόμενα για το PriceRange ComboBox
        DefaultComboBoxModel dlm =  (DefaultComboBoxModel) CreatePriceRangeComboBoxModel.getModel();
        //προσθέτω πρώτη γραμμή αδιάφορης επιλογής -> τιμή NOT_SELECTED
        dlm.insertElementAt(new cBoxItem("ΕΠΙΛΕΞΤΕ ΑΝΑΖΗΤΗΣΗ ΕΥΡΟΥΣ ΤΙΜΩΝ",NOT_SELECTED), 0);
        return  dlm;
    }
    
    private void findRestaurants(){
        // ανάκληση τιμών από την φόρμα
        String rName = NameTextField.getText().trim();
        
        ComplexItem.cBoxItem areaSelected =(ComplexItem.cBoxItem) AreaComboBox.getSelectedItem();
        ComplexItem.cBoxItem priceRangeSelected = (ComplexItem.cBoxItem) PriceRangeComboBox.getSelectedItem();
        ComplexItem.cListItem categorySelected =(ComplexItem.cListItem) CategoryList.getSelectedValue();
        int rArea= areaSelected.getIdItem();
        int rRange=priceRangeSelected.getIdItem();
        int rCategory= categorySelected.getIdItem();
        
        // μεταβλητή flag που καταγράφει λάθη στα πεδία της φόρμας
        boolean errors=false;
        // αρχικοποίηση μηνύματος λαθών
        String errorMessage="";
        
        // ανακαλώ όλη την λίστα εστιατορίων
        ArrayList<Restaurant> allRestaurants = new ArrayList<>();
        DBManager db= new DBManager();
        try {
            allRestaurants=db.getAllRestaurants();
        } catch (SQLException ex) {
            Logger.getLogger(UserSearchRestaurantGui.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            db.closeDB();
        } catch (SQLException ex) {
            Logger.getLogger(UserSearchRestaurantGui.class.getName()).log(Level.SEVERE, null, ex);
        }
        // Ελέγχω ποιά εστιατόρια εμπίπτουν στη λίστα
        ArrayList<Restaurant> filteredRestaurants = new ArrayList<>();
        filteredRestaurants.clear();
        boolean flagFilter=true;
        boolean flagIsChecked=false;
        if (!(allRestaurants==null)){
            // σημαία που δείχνει ότι εμπίπτει στα φίλτρα
            flagFilter=true;
            // σημαία που δείχνει ότι πέρασε από τουλάχιστον ένα φίλτρο
            flagIsChecked=false;
            // ανατρέχω σε ολα τα εστιατόρια
            for(Restaurant r: allRestaurants){
                flagFilter=true;
                flagIsChecked=false;
                // ελέγχω εάν το εστιατόριο φιλτράρετε με το όνομα
                if (!(rName.isEmpty())){
                   flagFilter=flagFilter && (rName.equals(r.getRestaurantName()));
                   flagIsChecked= flagIsChecked || true;
                }
                // ελέγχω εάν το εστιατόριο φιλτράρετε με την περιοχή 
                if (rArea!=NOT_SELECTED){
                    flagFilter=flagFilter && (rArea==r.getAreaId());
                    flagIsChecked= flagIsChecked || true;
                }
                // ελέγχω εάν το εστιατόριο φιλτράρετε με ευρος τιμων
                if (rRange!=NOT_SELECTED){
                    flagFilter=flagFilter && (rRange==r.getPriceRangeId());
                    flagIsChecked= flagIsChecked || true;
                }
                // ελέγχω εάν το εστιατόριο φιλτράρετε με κατηγορία
                if (rCategory!=NOT_SELECTED){
                    flagFilter=flagFilter && (rCategory==r.getCategoryId());
                    flagIsChecked= flagIsChecked || true;
                }
                // αν πέρασε από τουλάχιστον από ένα φίλτρο επιλέγετε
                if (flagFilter && flagIsChecked ){
                    filteredRestaurants.add(r);
                }
            }
            if (filteredRestaurants!=null){
                TableModel model =AllRestaurants.forTable(filteredRestaurants);
                ResultsTable.setModel(model);
                // αφαιρώ την πρώτη στήλη από τον πίνακα, ώστε το ID να μην εμφανίζεται
                TableColumn tcDeleteTable = ResultsTable.getColumnModel().getColumn(0);
                ResultsTable.getColumnModel().removeColumn(tcDeleteTable);
                // ρύθμιση μονής επιλογής στον πίνακα 
                ResultsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            }
        }
    }
    
    private void showRestaurantDialog(){
         // ανάκληση επιλλεγμένων γραμμών από τον πίνακα
        int[] rowIndices ;
        int rID;
        
        // όλες τις επιλεγμένες γραμμές στον πίνακα rowIndices
        rowIndices = ResultsTable.getSelectedRows();
        //εαν υπάρχουν επιλεγμένες γραμμές
        if (!(rowIndices.length==0)){
                // διάβασε το ID του εστιατορίου
                // βρίσκεται στην πρώτη στήλη του πίνακα
                // η οποία δεν εμφανίζεται στην φόρμα
                rID = (int) ResultsTable.getModel().getValueAt(rowIndices[0], 0);
                // ανακάλεσε τα στοιχεία του εστιατορίου 
                //και των συναφών πινάκων από την βάση δεδομένων
                findRestaurant(rID);
                RestaurantAddressLabel.setText(formRestaurant.getAddress());
                RestaurantNameLabel.setText(formRestaurant.getRestaurantName());
                RestaurantMoreTextArea.setText(formRestaurant.getDescription());
                RestaurantPhoneLabel.setText(formRestaurant.getPhone());
                RestaurantPriceLabel.setText(formPriceRange.toLabel());
                RestaurantInformationLabel.setText(formRestaurant.getInformation());
                RestaurantCategoryLabel.setText(formCategory.getCategoryName());
      
                if (formRating==null){
                   QualityStarRater.setRating(0);
                   PriceStarRater.setRating(0);
                   ServiceStarRater.setRating(0);
                   AverageStarRater.setRating(0);
                } else{
                   QualityStarRater.setRating(formRating.getQualityRate());
                   PriceStarRater.setRating(formRating.getPricesRate());
                   ServiceStarRater.setRating(formRating.getServiceRate());
                   AverageStarRater.setRating(formRating.getAverageRate());
                }
                
                RestaurantJXMapKit.setAddressLocation(restaurantguide.utils.Utils.getGeoposition(formArea.getAreaName()) );
                RestaurantJXMapKit.setZoom(1);
                ShowDialog.setLocationRelativeTo(this);
                ShowDialog.setVisible(true);
        } else {
            // μήνυμα μη επιλογής γραμμής στον πίνακα
            InformationMessage.show(this,"Πρέπει να επιλέξετε ενα εστιατόριο από τον πίνακα");
        }
    }
    
    private void rateRestaurantDialog(){
         // ανάκληση επιλλεγμένων γραμμών από τον πίνακα
        int[] rowIndices ;
        int rID;
        // όλες τις επιλεγμένες γραμμές στον πίνακα rowIndices
        rowIndices = ResultsTable.getSelectedRows();
        //εαν υπάρχουν επιλεγμένες γραμμές
        if (!(rowIndices.length==0)){
                // διάβασε το ID του εστιατορίου
                // βρίσκεται στην πρώτη στήλη του πίνακα
                // η οποία δεν εμφανίζεται στην φόρμα
                rID = (int) ResultsTable.getModel().getValueAt(rowIndices[0], 0);
                // ανακάλεσε τα στοιχεία του εστιατορίου και των συναφών πινάκων
                // από την βάση δεδομένων
                findRestaurant(rID);
                RateRestaurantNameLabel.setText(formRestaurant.getRestaurantName());
                 if (formRating==null){
                   RateQualityStarRater.setRating(0);
                   RatePriceStarRater.setRating(0);
                   RateServiceStarRater.setRating(0);
                   RateAverageStarRater.setRating(0);
                } else{
                   RateQualityStarRater.setRating(formRating.getQualityRate());
                   RatePriceStarRater.setRating(formRating.getPricesRate());
                   RateServiceStarRater.setRating(formRating.getServiceRate());
                   RateAverageStarRater.setRating(formRating.getAverageRate());
                }
                 RateQualityStarRater.setSelection(0);
                 RatePriceStarRater.setSelection(0);
                 RateServiceStarRater.setSelection(0);
                 RateAverageStarRater.setSelection(0);
                
                RateDialog.setLocationRelativeTo(this);
                RateDialog.setVisible(true);

        } else {
            // μήνυμα μη επιλογής γραμμής στον πίνακα
            InformationMessage.show(this,"Πρέπει να επιλέξετε ενα εστιατόριο από τον πίνακα");
        }
    }
    
    private void calculateFormAverageStarRater(){
        // λαμβάνω την τιμή selection αν είναι > 0
        float nrq = (RateQualityStarRater.getSelection()==0? RateQualityStarRater.getRating():RateQualityStarRater.getSelection());
        float nrp = (RatePriceStarRater.getSelection()==0? RatePriceStarRater.getRating():RatePriceStarRater.getSelection());
        float nrs = (RateServiceStarRater.getSelection()==0? RateServiceStarRater.getRating():RateServiceStarRater.getSelection());
        
       RateAverageStarRater.setSelection((int) (nrq + nrp + nrs)/3);
    }
    
    private void  formUpdateRatingFromUser(){
        float nrq = (RateQualityStarRater.getSelection()==0? RateQualityStarRater.getRating():RateQualityStarRater.getSelection());
        float nrp = (RatePriceStarRater.getSelection()==0? RatePriceStarRater.getRating():RatePriceStarRater.getSelection());
        float nrs = (RateServiceStarRater.getSelection()==0? RateServiceStarRater.getRating():RateServiceStarRater.getSelection());
       
        if ( nrq!=0 && nrp !=0 && nrs!=0){
            if (formRating == null){ // δεν υπάρχει βαθμολογία στην βάση δεδομένων
                Rating newRating = new Rating(loggedUser.getUserId(),formRestaurant.getRestId(), (int) nrq, (int) nrp, (int) nrs);
                try {
                    DBManager db = new DBManager();
                    db.addRating(newRating);
                    db.closeDB();
                    RateQualityStarRater.setRating(newRating.getQualityRate());
                    RatePriceStarRater.setRating(newRating.getPricesRate());
                    RateServiceStarRater.setRating(newRating.getServiceRate());
                    RateAverageStarRater.setRating(newRating.getAverageRate());
                    // μήνυμα εγγραφής στην βάση δεδομένων
                    formRating=newRating;
                    InformationMessage.show(this,"Η αξιολόγηση σας καταχωρήθηκε");
                } catch (SQLException ex) {
                    // μήνυμα αποτυχίας εγγραφής στην βάση δεδομένων
                    InformationMessage.show(this,"Η αξιολόγηση σας δεν καταχωρήθηκε /nυπάρχει κάποιο πρόβλημα με την βάση δεδομένων ");
                    Logger.getLogger(UserSearchRestaurantGui.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else{ // υπάρχει βαθμολογία στην βάση δεδομένων
                Rating newRating = new Rating(loggedUser.getUserId(),formRestaurant.getRestId(), (int) nrq, (int) nrp, (int) nrs);
                try {
                    DBManager db = new DBManager();
                    db.updateRating(newRating);
                    db.closeDB();
                    RateQualityStarRater.setRating(newRating.getQualityRate());
                    RatePriceStarRater.setRating(newRating.getPricesRate());
                    RateServiceStarRater.setRating(newRating.getServiceRate());
                    RateAverageStarRater.setRating(newRating.getAverageRate());
                    formRating=newRating;
                    // μήνυμα εγγραφής στην βάση δεδομένων
                    InformationMessage.show(this,"Η αξιολόγηση σας καταχωρήθηκε");
                } catch (SQLException ex) {
                    // μήνυμα αποτυχίας εγγραφής στην βάση δεδομένων
                    InformationMessage.show(this,"Η αξιολόγηση σας δεν καταχωρήθηκε /nυπάρχει κάποιο πρόβλημα με την βάση δεδομένων ");
                    Logger.getLogger(UserSearchRestaurantGui.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
            
    
    private void reserveRestaurantDialog(){
         // ανάκληση επιλλεγμένων γραμμών από τον πίνακα
        int[] rowIndices ;
        int rID;
        // όλες τις επιλεγμένες γραμμές στον πίνακα rowIndices
        rowIndices = ResultsTable.getSelectedRows();
        //εαν υπάρχουν επιλεγμένες γραμμές
        if (!(rowIndices.length==0)){
                // διάβασε το ID του εστιατορίου
                // βρίσκεται στην πρώτη στήλη του πίνακα
                // η οποία δεν εμφανίζεται στην φόρμα
                rID = (int) ResultsTable.getModel().getValueAt(rowIndices[0], 0);
                ReserveDialog.setLocationRelativeTo(this);
                ReserveDialog.setVisible(true);
        } else {
            // μήνυμα μη επιλογής γραμμής στον πίνακα
            InformationMessage.show(this,"Πρέπει να επιλέξετε ενα εστιατόριο από τον πίνακα");
        }
    }
    
    // βρίσκει το εστιατόριο και όλα τα στοιχεία που είναι συνδεδεμένα με αυτό
    // από την βάση δεδομένων, με βάση την επιλογή του πίνακα και το loggedUser
    private void findRestaurant(int rID){
        try {
            DBManager db = new DBManager();
             // ανακάλεσε τα αρχεία του εστιατόριου από την βάση δεδομένων
             formRestaurant = db.getRestaurantById(rID);
             formArea = db.getAreaById(formRestaurant.getAreaId());
             formCategory = db.getCategoryById(formRestaurant.getCategoryId());
             formRating=db.getRating(loggedUser.getUserId(), formRestaurant.getRestId());
             formPriceRange=db.getPriceRangeById(formRestaurant.getPriceRangeId());
             
             db.closeDB();
        } catch (SQLException ex) {
            Logger.getLogger(UserSearchRestaurantGui.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
